package com.hbnu.tangyalu.thread;

public class Ticket implements Runnable{
    private int ticket=30;
//显示锁，手动开锁和关锁 只有代码块锁
//    private final Re
    @Override
//    synchronized有锁代码块锁和方法锁
//    public synchronized void run(){
    public void run(){
        while(true){
//            lock.lock();
            synchronized (this){
                if (ticket>0){
                    System.out.println(Thread.currentThread().getName()+"卖出第"+ticket+"号票");
                    ticket--;
                }
                else {
                    break;
                }
            }

        }
    }
}
